<!--全站搜索 -->
<div class="pageso J_so">

  <div class="tox">
  	<div class="back J_so_back"></div>
	<div class="sobox">
 
	<input name="key" type="text"  class="J_key" maxlength="12" placeholder="请在这里输入关键字"  value="{$Think.get.key}"  />
	<div class="clearkey J_clearkey"></div>
 
	</div>
	<div class="sobtn font14" id="J_sobtnSubmit">搜索</div>
  </div>
  
  
  <div class="bxt font12 J_show_cache_keywords">
    <div class="t"><strong>最近搜索</strong><div class="cleankey J_cleankeyall"></div></div>
	
	<!--<a class="li" href="@">缓存关键字</a> -->
  </div>
  
  <div class="bxt font12">
    <div class="t"><strong>热门话题</strong></div>
	
	  <ytata:tag listname="tags"  page="0" sort="hot" num="40"/>
		<volist name="tags.list" id="tli">
        <div class="li J_ctagli" url="{$tli.url}">{$tli.tag}<span>({$tli.count_question})</span></div>
		</volist>
 
	
  </div>
  
  
</div>
<script>
$(".J_show_so").off().on('click',function(){	
	$(".J_so").show();
	$(".J_so").find('input').focus();
	$(".J_clearkey").show();
	//关闭
	$(".J_so_back").off().on('click',function(){
		$(".J_so").hide();
	});
	//清除文本框关键字
		$(".J_clearkey").off().on('click',function(){
			$(".J_key").val('');
		});
	//清除关键字（历史关键字）
		$(".J_cleankeyall").off().on('click',function(){
			$(".J_show_cache_keywords").find('a').remove();
			localStorage.setItem("cache_keywords",'');
	});
	 
	//从缓存获取最近搜搜
	var cache_keywords=localStorage.getItem("cache_keywords");
    if(cache_keywords) {
		$(".J_show_cache_keywords").show();
		$(".J_show_cache_keywords").find('a').remove();
		var keyArr = cache_keywords.split('--|,|').reverse();
		for (var i = 0; i < 15; i++) {
			console.log(keyArr[i]);
			var url="{:U('so/view')}&key=" + keyArr[i];
			if (keyArr[i]) {
				$(".J_show_cache_keywords").append('<a class="li" href='+url+'>'+keyArr[i]+'</a>');
			}
		}
	}else{
		$(".J_show_cache_keywords").hide();
	}
	//alert(cache_keywords);

});

$("#J_sobtnSubmit").off().on('click',function(){
	 var key = $(".J_key").val();
	 $(".J_so").hide();
	 if (key.length) {
	 	var cache_keywords=localStorage.getItem("cache_keywords");
	 	if (cache_keywords) {
			if ($.inArray(key,cache_keywords.split('--|,|')) < 0) {
				cache_keywords = cache_keywords.split('--|,|').concat(key);
				localStorage.setItem("cache_keywords",cache_keywords.join('--|,|'));
			}
		} else {
			localStorage.setItem("cache_keywords",key);
		}
	 }
	 location.href = "{:U('so/view')}&key=" + key;  
});
//点击热门话题事件
 $(".J_ctagli").off().on('click',function(){
	 $(".J_so").hide();
	 location.href = $(this).attr('url');  
});
 
 

 

</script>